/*
 * DppmParams.cpp
 *
 *  Created on: 20/01/2014
 *      Author: root
 */

#include <stdlib.h>
#include <iostream>
using namespace std;
#include "DppmParams.h"

void InitializeDppm(DppmParams &dppm, int numAct, int T, int* numPreds, int** Preds, int* numModes, int** ModesCosts, int** ModesTimes){
	dppm.numAct = numAct;
	dppm.deadline = T;
	dppm.acts = new Activity[numAct];

	for(int i = 0; i < numAct ; i++){

		if (Preds[i] == NULL){
			dppm.acts[i].numPreds = 0;
			dppm.acts[i].preds = NULL;
		}
		else{
			dppm.acts[i].numPreds = numPreds[i];
			dppm.acts[i].preds = new int[dppm.acts[i].numPreds];

			for(int j = 0; j < dppm.acts[i].numPreds; j++)
				dppm.acts[i].preds[j] = Preds[i][j];
		}

		if(ModesCosts[i] == NULL){
			dppm.acts[i].numModes = 0;
			dppm.acts[i].costs = NULL;
			dppm.acts[i].times = NULL;
		}
		else{
			dppm.acts[i].numModes = numModes[i];
			dppm.acts[i].costs = new int[dppm.acts[i].numModes];
			dppm.acts[i].times = new int[dppm.acts[i].numModes];

			for(int j = 0; j < dppm.acts[i].numModes; j++){
				dppm.acts[i].costs[j] = ModesCosts[i][j];
				dppm.acts[i].times[j] = ModesTimes[i][j];
			}
		}
	}
}

//void SetActivityModes(DppmParams &dppm, int actId, int numModes, int* Costs, int* Times){
//	dppm.modes[actId].numModes = numModes;
//	dppm.modes[actId].costs = new int[numModes];
//	dppm.modes[actId].times = new int[numModes];
//
//	for(int i = 0; i < numModes; i++){
//		dppm.modes[actId].costs[i] = Costs[i];
//		dppm.modes[actId].times[i] = Times[i];
//	}
//}

void FreeMemory(DppmParams &dppm){
	for(int i = 0; i < dppm.numAct; i++){
		delete [] dppm.acts[i].preds;
		delete [] dppm.acts[i].costs;
		delete [] dppm.acts[i].times;
	}
	delete dppm.acts;
}


int GetDeadline(DppmParams &dppm){
	return dppm.deadline;
}

int GetNumActivities(DppmParams &dppm){
	return dppm.numAct;
}

int GetActivityNumModes(DppmParams &dppm, int act){
	return dppm.acts[act].numModes;
}

int* GetActivityModesCosts(DppmParams &dppm, int act){
	return dppm.acts[act].costs;
}

int* GetActivityModesTimes(DppmParams &dppm, int act){
	return dppm.acts[act].times;
}

int GetActivityNumPreds(DppmParams &dppm, int act){
	return dppm.acts[act].numPreds;
}

int* GetActivityPreds(DppmParams &dppm, int act){
	return dppm.acts[act].preds;
}

int GetPartialSolutionCost(DppmParams &dppm, int* R, int lastAct){
	int solutionCost = 0;
	for (int i = 0; i < lastAct; i++){
		solutionCost += dppm.acts[i].costs[R[i]];
	}
	return solutionCost;
}

int GetSolutionCost(DppmParams &dppm, int* R){
	return GetPartialSolutionCost(dppm, R, dppm.numAct);
}









